package com.the4man.framework.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.framework.cache.PermissionCache;
import com.the4man.framework.model.*;
import com.the4man.framework.pagemodel.*;
import com.the4man.framework.pagemodel.PPage;
import com.the4man.framework.service.MenuServiceI;
import com.the4man.framework.service.SystemManagerServiceI;
import com.the4man.framework.util.DateUtil;
import com.the4man.framework.util.EncryptUtil;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import com.the4man.framework.utils.InitParamUtil;
import com.the4man.framework.utils.RequestUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by lenovo on 2017/12/12.
 */
@Action(
        value = "systemManagerAction",
        results = {@Result(
                name = "personal_data",
                location = "/framework/systemManager/user/personal_data.jsp"
        ), @Result(
                name = "user_manager",
                location = "/framework/systemManager/user/user_manager.jsp"
        ), @Result(
                name = "user_manager_modifyuser",
                location = "/framework/systemManager/user/user_manager_modifyuser.jsp"
        ), @Result(
                name = "moudle_manager",
                location = "/framework/systemManager/moudle/moudle_manager.jsp"
        ), @Result(
                name = "role_newrole_limitmoudle",
                location = "/framework/systemManager/role/role_newrole_limitmoudle.jsp"
        ), @Result(
                name = "role_modifyrole_limitmoudle",
                location = "/framework/systemManager/role/role_modifyrole_limitmoudle.jsp"
        ), @Result(
                name = "role_assign_permission",
                location = "/framework/systemManager/role/role_assign_permission.jsp"
        ), @Result(
                name = "department_manager",
                location = "/framework/systemManager/department/department_manager.jsp"
        ), @Result(
                name = "department_manager_edit",
                location = "/framework/systemManager/department/department_manager_edit.jsp"
        ), @Result(
                name = "role_manager",
                location = "/framework/systemManager/role/role_manager.jsp"
        )}
)
public class SystemManagerAction extends BaseAction implements ModelDriven<PSystemManager> {
    private static final long serialVersionUID = -5031434423590141426L;
    private static final Logger logger = LoggerFactory.getLogger(SystemManagerAction.class);
    PSystemManager pSystemManager = new PSystemManager();
    @Autowired
    private SystemManagerServiceI systemManagerService;
    @Autowired
    private MenuServiceI menuService;
    @Resource
    private PermissionCache permissionCache;

    public SystemManagerAction() {
    }

    public String executeMangerResult() {
        return "user_manager";
    }

    public String executeResult() {
        return "personal_data";
    }

    public String executeModifyResult() {
        String forword = "";

        try {
            User user = this.systemManagerService.getUserInfo(this.pSystemManager);
            RequestUtil.putHttpSessionObject("pSystemManager", user);
            forword = "user_manager_modifyuser";
        } catch (Exception var3) {
            logger.error("获取用户信息出错了" + var3.toString());
            forword = "user_manager_modifyuser";
        }

        return forword;
    }

    public void validataUserId() {
        PageJson json = new PageJson();

        try {
            User user = this.systemManagerService.getUserInfo(this.pSystemManager);
            if(user != null && StringUtils.isNotEmpty(user.getUserid())) {
                json.setReturnMsg("用户账号已被占用,请更换用户账号！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("验证用户账号是否存在！" + var3.toString());
            json.setReturnMsg("");
            json.setReturnFlag(false);
            this.writeJson(json);
        }

    }

    public void modifyUserInfo() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.modifyUserInfo(this.pSystemManager);
            if(b) {
                json.setReturnMsg("修改用户成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("修改用户失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("修改用户失败了" + var3.toString());
            json.setReturnMsg("修改用户失败！");
            json.setReturnFlag(false);
        }

    }

    public void deleteBatchUser() {
        PageJson json = new PageJson();

        try {
            new HashMap();
            String[] userIdArray = new String[0];
            if(this.pSystemManager.getBatchFlag().equals("true")) {
                userIdArray = this.pSystemManager.getUserid().split(",");
            } else {
                userIdArray = this.pSystemManager.getPid().split(",");
            }

            List<String> delList = new ArrayList();
            String[] var8 = userIdArray;
            int var7 = userIdArray.length;

            for(int var6 = 0; var6 < var7; ++var6) {
                String str = var8[var6];
                delList.add(str.trim());
            }

            boolean b = this.systemManagerService.deleteBatchUser(delList);
            if(b) {
                json.setReturnMsg("删除用户成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("删除用户失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var9) {
            logger.error("批量删除用户失败！", var9.toString());
            json.setReturnMsg("删除用户失败！");
            json.setReturnFlag(false);
        }

    }

    public void addUserInfo() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.addUserInfo(this.pSystemManager);
            if(b) {
                json.setReturnMsg("新建用户成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("新建用户成功失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("新建用户失败了" + var3.toString());
            json.setReturnMsg("新建用户失败！");
            json.setReturnFlag(false);
        }

    }

    public void getSelectRoleData() {
        try {
            new ArrayList();
            List<Role> listData = this.systemManagerService.getEtlRoleData(this.pSystemManager);
            Role role = new Role();
            role.setRoleid("");
            role.setRolename("全部");
            List<Role> listFinal = new ArrayList();
            listFinal.add(role);
            Iterator var5 = listData.iterator();

            while(var5.hasNext()) {
                Role r = (Role)var5.next();
                listFinal.add(r);
            }

            this.writeJson(listFinal);
        } catch (Exception var6) {
            logger.error("获取用户角色下拉框数据" + var6.toString());
        }

    }

    public void saveUserDetail() {
        PageJson json = new PageJson();

        try {
            this.pSystemManager.setStatus("0");
            boolean b = this.systemManagerService.saveUserDetail(this.pSystemManager);
            if(b) {
                json.setReturnMsg("用户资料保存成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("用户资料保存失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("保存用户详细资料出错了" + var3.toString());
            json.setReturnMsg("用户资料保存失败！");
            json.setReturnFlag(false);
        }

    }

    public void modifyUserPwd() {
        PageJson json = new PageJson();

        try {
            User user = this.systemManagerService.getUserInfo(this.pSystemManager);
            if(!user.getUserpwd().equals(EncryptUtil.getInstance().encryptMD5(this.pSystemManager.getUseroldpwd()))) {
                json.setReturnMsg("输入原密码不正确！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                this.pSystemManager.setStatus("2");
                boolean b = this.systemManagerService.saveUserDetail(this.pSystemManager);
                if(b) {
                    json.setReturnMsg("用户密码修改成功！");
                    json.setReturnFlag(true);
                    this.writeJson(json);
                } else {
                    json.setReturnMsg("用户密码修改失败！");
                    json.setReturnFlag(false);
                    this.writeJson(json);
                }
            }
        } catch (Exception var4) {
            logger.error("保存用户密码出错了" + var4.toString());
            json.setReturnMsg("用户密码保存失败！");
            json.setReturnFlag(false);
        }

    }

    public void saveHeadPicture() {
        PageJson json = new PageJson();

        try {
            this.pSystemManager.setStatus("1");
            boolean b = this.systemManagerService.saveUserDetail(this.pSystemManager);
            if(b) {
                json.setReturnMsg("保存用户头像成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
                PUser puser = (PUser)RequestUtil.getHttpSessionObject(InitParamUtil.getSessionInfoName());
                puser.setPicpath(this.pSystemManager.getPicpath());
                RequestUtil.putHttpSessionObject(InitParamUtil.getSessionInfoName(), puser);
            } else {
                json.setReturnMsg("保存用户头像失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var4) {
            logger.error("上传头像成功！" + var4.toString());
            json.setReturnMsg("保存用户头像失败！");
            json.setReturnFlag(false);
        }

    }

    public String getUserInfo() {
        String forword = "";

        try {
            User user = this.systemManagerService.getUserInfo(this.pSystemManager);
            RequestUtil.removeSessionObject(InitParamUtil.getSessionInfoName());
            PUser puser = new PUser();
            BeanUtils.copyProperties(user, puser);
            RequestUtil.putHttpSessionObject(InitParamUtil.getSessionInfoName(), puser);
            forword = "personal_data";
        } catch (Exception var4) {
            logger.error("获取用户信息出错了" + var4.toString());
            forword = "personal_data";
        }

        return forword;
    }

    public String uploadFile() throws Exception {
        String forword = "";
        String realpath = this.getClass().getClassLoader().getResource(File.separator).getPath();
        int endIndex = realpath.indexOf("/WEB-INF");
        realpath = realpath.substring(0, endIndex) + "/images/headpicture/customHead/";
        String content = ServletActionContext.getServletContext().getContextPath();
        int pos = this.pSystemManager.getFiledataFileName().lastIndexOf(".");
        String fileExt = this.pSystemManager.getFiledataFileName().substring(pos);
        String newFileName = UUID.randomUUID().toString().replaceAll("-", "") + fileExt;
        new SimpleDateFormat("yyyyMMdd");
        File uploadDir = new File(realpath);
        if(!uploadDir.exists()) {
            uploadDir.mkdirs();
        }

        String err = "";
        if(this.pSystemManager.getFiledata() != null) {
            File savefile = new File(new File(realpath), newFileName);
            if(!savefile.getParentFile().exists()) {
                savefile.getParentFile().mkdirs();
            }

            FileUtils.copyFile(this.pSystemManager.getFiledata(), savefile);
        } else {
            logger.error("上传自定义头像失败!");
        }

        String tempPath = content + "/images/headpicture/customHead/" + newFileName;
        this.pSystemManager.setStatus("1");
        this.pSystemManager.setPicpath(tempPath);
        boolean b = this.systemManagerService.saveUserDetail(this.pSystemManager);
        if(b) {
            logger.error("上传头像成功!");
            PUser puser = (PUser)RequestUtil.getHttpSessionObject(InitParamUtil.getSessionInfoName());
            puser.setPicpath(tempPath);
            RequestUtil.putHttpSessionObject(InitParamUtil.getSessionInfoName(), puser);
        } else {
            logger.error("上传头像失败!");
        }

        return "personal_data";
    }

    public String executeRoleResult() {
        return "role_manager";
    }

    public void ValidRoleContainUser() {
        PageJson json = new PageJson();

        try {
            new ArrayList();
            List<User> listData = this.systemManagerService.getAllUserInfo(this.pSystemManager);
            if(listData.size() > 0) {
                json.setReturnFlag(true);
                json.setReturnMsg("请取消该角色下所授权的所有用户!");
                this.writeJson(json);
            } else {
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("验证功能角色下，包含多少用户" + var3.toString());
            json.setReturnFlag(false);
            json.setReturnMsg("");
            this.writeJson(json);
        }

    }

    public String newLimitRoleResult() {
        String forword = "";

        try {
            new ArrayList();
            List<Moudle> listData = this.systemManagerService.getEtlMoudleData(this.pSystemManager);
            RequestUtil.putOgnlObject("moudleList", listData);
            forword = "role_newrole_limitmoudle";
        } catch (Exception var3) {
            ;
        }

        return forword;
    }

    public String doAssignPermissionResult() {
        return "role_assign_permission";
    }

    public void assignPermission() {
        PageJson json = new PageJson();

        try {
            this.systemManagerService.assignPermission(this.pSystemManager.getRoleid(), this.pSystemManager.getPermissionIds());
            json.setReturnMsg("分配权限成功");
            json.setReturnFlag(true);
        } catch (Exception var3) {
            json.setReturnMsg("分配权限出现异常");
            json.setReturnFlag(false);
            LOG.error(json.getReturnMsg() + var3.getMessage(), var3, new String[0]);
        }

        this.writeJson(json);
    }

    public void menulist() {
        try {
            String roleid = this.pSystemManager.getRoleid();
            HashSet<String> permissionUrls = this.permissionCache.getPermissionByRoleId(roleid);
            Iterator iterator = permissionUrls.iterator();

            while(iterator.hasNext()) {
                String permissionUrl = (String)iterator.next();
                System.out.println("已授权URL: " + permissionUrl);
            }

            List<PMenu> treeMenus = this.menuService.getAllTreeMenu();

            PMenu next;
            HashMap properties;
            for(iterator = treeMenus.iterator(); iterator.hasNext(); next.setAttributes(properties)) {
                next = (PMenu)iterator.next();
                if(StringUtils.equals(next.getPmoudleid(), "SYSTEM")) {
                    iterator.remove();
                }

                properties = new HashMap();
                if(permissionUrls != null && permissionUrls.contains(next.getUrl())) {
                    System.out.println(next.getText());
                    properties.put("status", Boolean.valueOf(true));
                } else {
                    properties.put("status", Boolean.valueOf(false));
                }

                if(org.apache.commons.lang.StringUtils.isBlank(next.getPid())) {
                    System.out.println(next.getText());
                    properties.put("status", Boolean.valueOf(true));
                }
            }

            this.writeJson(treeMenus);
        } catch (Exception var7) {
            var7.printStackTrace();
        }

    }

    public String modifyLimitRoleResult() {
        String forword = "";

        try {
            new ArrayList();
            List<Moudle> listData = this.systemManagerService.getEtlMoudleData(this.pSystemManager);
            RequestUtil.putOgnlObject("moudleList", listData);
            new ArrayList();
            List<Role> roleList = this.systemManagerService.getEtlRoleData(this.pSystemManager);
            Role role = (Role)roleList.get(0);
            RequestUtil.putOgnlObject("role", role);
            forword = "role_modifyrole_limitmoudle";
        } catch (Exception var5) {
            ;
        }

        return forword;
    }

    public void getEtlRoleData() {
        String key = "com.the4man.framework.dao.SystemManagerMapper.getEtlRoleData";

        try {
            PPage page = new PPage();
            PageContext.getContext().putSession(key, page);
            BeanUtils.copyProperties(this.pSystemManager, page);
            DataGrid d = new DataGrid();
            List<Role> listData = this.systemManagerService.getEtlRoleData(this.pSystemManager);
            Iterator var6 = listData.iterator();

            while(var6.hasNext()) {
                Role role = (Role)var6.next();
                this.pSystemManager.setRoleid(role.getRoleid());
                new ArrayList();
                List<Moudle> list = this.systemManagerService.getMoudleDataByRole(this.pSystemManager);
                StringBuffer str = new StringBuffer();
                Iterator var10 = list.iterator();

                while(var10.hasNext()) {
                    Moudle m = (Moudle)var10.next();
                    if(StringUtils.isNotEmpty(m.getMoudleid())) {
                        str.append(m.getMoudlename() + ";\t");
                    }
                }

                role.setLimitModule(str.toString());
            }

            d.setRows(listData);
            d.setTotal(Long.valueOf(page.getTotals()));
            this.writeJson(d);
        } catch (Exception var14) {
            logger.error("获取用户角色数据失败" + var14.toString());
        } finally {
            PageContext.getContext().removeSession(key);
        }

    }

    public void getMoudleDataByRole() {
        try {
            new ArrayList();
            List<Moudle> currlist = this.systemManagerService.getMoudleDataByRole(this.pSystemManager);
            new ArrayList();
            List<Moudle> allList = this.systemManagerService.getEtlMoudleData(this.pSystemManager);
            Map<String, List> map = new HashMap();
            map.put("currlist", currlist);
            map.put("allList", allList);
            this.writeJson(map);
        } catch (Exception var4) {
            logger.error("根据用户角色获取当前授权的功能模块" + var4.toString());
        }

    }

    public void loadComboxData() {
        try {
            new ArrayList();
            List<Role> listData = this.systemManagerService.getEtlRoleData(this.pSystemManager);
            this.writeJson(listData);
        } catch (Exception var2) {
            logger.error("加载用户角色数据失败!" + var2.toString());
        }

    }

    public void addRoleData() {
        PageJson json = new PageJson();

        try {
            String tempStr = DateUtil.getInstance().getTimeStamp();
            this.pSystemManager.setRoleid(tempStr.substring(11, tempStr.length()));
            boolean b = this.systemManagerService.addRoleData(this.pSystemManager);
            String[] moudleArray = new String[0];
            if(StringUtils.isNotEmpty(this.pSystemManager.getMoudleid())) {
                moudleArray = this.pSystemManager.getMoudleid().split("@@");

                for(int idx = 0; idx < moudleArray.length; ++idx) {
                    this.pSystemManager.setMoudleid(moudleArray[idx]);
                    this.pSystemManager.setDisOrder(Integer.valueOf(idx + 1));
                    int var6 = this.systemManagerService.insertLimitRoleModule(this.pSystemManager);
                }
            }

            if(b) {
                json.setReturnMsg("新增用户角色成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("新增用户角色失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var7) {
            logger.error("增加用户角色数据失败" + var7.toString());
            json.setReturnMsg("新增用户角色失败！");
            json.setReturnFlag(false);
        }

    }

    public void deleteBatchRole() {
        PageJson json = new PageJson();

        try {
            new HashMap();
            String[] roleArray = new String[0];
            if(this.pSystemManager.getBatchFlag().equals("true")) {
                roleArray = this.pSystemManager.getRoleid().split(",");
            } else {
                roleArray = this.pSystemManager.getPid().split(",");
            }

            List<String> delList = new ArrayList();
            String[] var8 = roleArray;
            int var7 = roleArray.length;

            for(int var6 = 0; var6 < var7; ++var6) {
                String str = var8[var6];
                delList.add(str.trim());
            }

            boolean b = this.systemManagerService.deleteBatchRole(delList);
            if(b) {
                json.setReturnMsg("删除用户角色成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("删除用户角色成功！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var9) {
            logger.error("批量删除用户角色失败！", var9.toString());
            json.setReturnMsg("删除用户角色成功！");
            json.setReturnFlag(false);
        }

    }

    public void modifyRoleData() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.modifyRoleData(this.pSystemManager);
            int deleMoudle = this.systemManagerService.deleteCurrentRoleModule(this.pSystemManager);
            String[] moudleArray = new String[0];
            if(StringUtils.isNotEmpty(this.pSystemManager.getMoudleid())) {
                moudleArray = this.pSystemManager.getMoudleid().split("@@");

                for(int idx = 0; idx < moudleArray.length; ++idx) {
                    this.pSystemManager.setMoudleid(moudleArray[idx]);
                    this.pSystemManager.setDisOrder(Integer.valueOf(idx + 1));
                    int var6 = this.systemManagerService.insertLimitRoleModule(this.pSystemManager);
                }
            }

            if(b) {
                json.setReturnMsg("修改用户角色成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("修改用户角色失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var7) {
            logger.error("修改用户角色出错了" + var7.toString());
            json.setReturnMsg("修改用户角色失败！");
            json.setReturnFlag(false);
        }

    }

    public void getAllUserInfo() {
        String key = "com.the4man.framework.dao.SystemManagerMapper.getAllUserInfo";

        try {
            PPage page = new PPage();
            PageContext.getContext().putSession(key, page);
            BeanUtils.copyProperties(this.pSystemManager, page);
            DataGrid d = new DataGrid();
            d.setRows(this.systemManagerService.getAllUserInfo(this.pSystemManager));
            d.setTotal(Long.valueOf(page.getTotals()));
            this.writeJson(d);
        } catch (Exception var7) {
            logger.error("获取系统所用用户出错了" + var7.toString());
        } finally {
            PageContext.getContext().removeSession(key);
        }

    }

    public void validRoleName() {
        PageJson json = new PageJson();

        try {
            json.setReturnFlag(this.systemManagerService.checkRoleName(this.pSystemManager));
            this.writeJson(json);
        } catch (Exception var3) {
            logger.error("验证用户角色名称是否存在" + var3.toString());
            json.setReturnMsg("验证用户角色名称是否存在！");
            json.setReturnFlag(false);
        }

    }

    public String executeModuleResult() {
        return "moudle_manager";
    }

    public void ValidMoudleContainRole() {
        PageJson json = new PageJson();

        try {
            new ArrayList();
            List<Moudle> listData = this.systemManagerService.getMoudleDataByRole(this.pSystemManager);
            if(listData.size() > 0) {
                json.setReturnFlag(true);
                json.setReturnMsg("请取消该模块下所授权的所有用户角色!");
                this.writeJson(json);
            } else {
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("验证功能模块下，包含多少用户角色" + var3.toString());
            json.setReturnFlag(false);
            json.setReturnMsg("");
            this.writeJson(json);
        }

    }

    public void getEtlMoudleData() {
        String key = "com.the4man.framework.dao.SystemManagerMapper.getEtlMoudleData";

        try {
            PPage page = new PPage();
            PageContext.getContext().putSession(key, page);
            BeanUtils.copyProperties(this.pSystemManager, page);
            DataGrid d = new DataGrid();
            d.setRows(this.systemManagerService.getEtlMoudleData(this.pSystemManager));
            d.setTotal(Long.valueOf(page.getTotals()));
            this.writeJson(d);
        } catch (Exception var7) {
            logger.error("获取系统模块数据失败" + var7.toString());
        } finally {
            PageContext.getContext().removeSession(key);
        }

    }

    public void addMoudleData() {
        PageJson json = new PageJson();

        try {
            String tempStr = DateUtil.getInstance().getTimeStamp();
            this.pSystemManager.setMoudleid(tempStr.substring(10, tempStr.length()));
            boolean b = this.systemManagerService.addMoudleData(this.pSystemManager);
            if(b) {
                json.setReturnMsg("新增系统模块成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("新增系统模块失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var4) {
            logger.error("新增系统模块失败" + var4.toString());
            json.setReturnMsg("新增系统模块失败！");
            json.setReturnFlag(false);
        }

    }

    public void deleteBatchMoudle() {
        PageJson json = new PageJson();

        try {
            new HashMap();
            String[] moudleIdArray = new String[0];
            if(this.pSystemManager.getBatchFlag().equals("true")) {
                moudleIdArray = this.pSystemManager.getMoudleid().split(",");
            } else {
                moudleIdArray = this.pSystemManager.getPid().split(",");
            }

            List<String> delList = new ArrayList();
            String[] var8 = moudleIdArray;
            int var7 = moudleIdArray.length;

            for(int var6 = 0; var6 < var7; ++var6) {
                String str = var8[var6];
                delList.add(str.trim());
            }

            boolean b = this.systemManagerService.deleteBatchMoudle(delList);
            if(b) {
                json.setReturnMsg("删除系统模块成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("删除系统模块失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var9) {
            logger.error("删除系统模块失败！", var9.toString());
            json.setReturnMsg("删除系统模块失败！");
            json.setReturnFlag(false);
        }

    }

    public void modifyMoudleData() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.modifyMoudleData(this.pSystemManager);
            if(b) {
                json.setReturnMsg("修改系统模块成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("修改系统模块失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("修改系统模块出错了" + var3.toString());
            json.setReturnMsg("修改系统模块失败！");
            json.setReturnFlag(false);
        }

    }

    public void validMoudleName() {
        PageJson json = new PageJson();

        try {
            json.setReturnFlag(this.systemManagerService.checkMoudleName(this.pSystemManager));
            this.writeJson(json);
        } catch (Exception var3) {
            logger.error("验证用户模块名称是否存在" + var3.toString());
            json.setReturnMsg("验证用户模块名称是否存在！");
            json.setReturnFlag(false);
        }

    }

    public String executeDepartmentResult() {
        return "department_manager";
    }

    public void getEtlDepartmentData() {
        try {
            new ArrayList();
            List<Department> listData = this.systemManagerService.getEtlDepartmentData(this.pSystemManager);
            this.writeJson(listData);
        } catch (Exception var2) {
            logger.error("获取部门管理所有数据" + var2.toString());
        }

    }

    public void addDepartment() {
        PageJson json = new PageJson();

        try {
            if(this.pSystemManager.getPdeptId().equals("parent")) {
                this.pSystemManager.setPdeptId("");
            }

            boolean b = this.systemManagerService.addDepartment(this.pSystemManager);
            if(b) {
                json.setReturnMsg("增加系统部门成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("增加系统部门失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("增加系统部门失败" + var3.toString());
            json.setReturnMsg("增加系统部门失败！");
            json.setReturnFlag(false);
        }

    }

    public void deleteDepartment() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.deleteDepartment(this.pSystemManager);
            if(b) {
                json.setReturnMsg("删除系统部门成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("删除系统部门失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("删除系统部门失败" + var3.toString());
            json.setReturnMsg("删除系统部门失败！");
            json.setReturnFlag(false);
        }

    }

    public String modifyDepartment() {
        String forword = "";

        try {
            new ArrayList();
            this.pSystemManager.setStatus("1");
            List<Department> listData = this.systemManagerService.modifyDepartment(this.pSystemManager);
            Department Department = (Department)listData.get(0);
            RequestUtil.putOgnlObject("department", Department);
            forword = "department_manager_edit";
        } catch (Exception var4) {
            ;
        }

        return forword;
    }

    public void modifyDepartmentData() {
        PageJson json = new PageJson();

        try {
            boolean b = this.systemManagerService.modifyDepartmentData(this.pSystemManager);
            if(b) {
                json.setReturnMsg("修改系统部门成功！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("修改系统部门失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("修改系统部门失败" + var3.toString());
            json.setReturnMsg("修改系统部门失败！");
            json.setReturnFlag(false);
        }

    }

    public void ValidDepartMentContainUser() {
        PageJson json = new PageJson();

        try {
            List<User> list = this.systemManagerService.getAllUserInfo(this.pSystemManager);
            this.pSystemManager.setStatus("1");
            this.pSystemManager.setPdeptId(this.pSystemManager.getDeptId());
            this.pSystemManager.setDeptId("");
            List<Department> listDepart = this.systemManagerService.getEtlDepartmentData(this.pSystemManager);
            if(list.size() > 0) {
                json.setReturnMsg("请取消该部门下所有用户！");
                json.setReturnFlag(true);
                this.writeJson(json);
                return;
            }

            if(listDepart.size() > 0) {
                json.setReturnMsg("请删除该部门下所有子部门！");
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnMsg("删除该部门失败！");
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var4) {
            logger.error("请取消该部门下所有用户" + var4.toString());
            json.setReturnMsg("请取消该部门下所有用户！");
            json.setReturnFlag(false);
        }

    }

    public void validDeptName() {
        PageJson json = new PageJson();

        try {
            new ArrayList();
            this.pSystemManager.setStatus("1");
            List<Department> listData = this.systemManagerService.getEtlDepartmentData(this.pSystemManager);
            if(listData.size() > 0) {
                json.setReturnFlag(true);
                this.writeJson(json);
            } else {
                json.setReturnFlag(false);
                this.writeJson(json);
            }
        } catch (Exception var3) {
            logger.error("验证用户部门名称是否存在" + var3.toString());
            json.setReturnMsg("验证用户部门名称是否存在！");
            json.setReturnFlag(false);
        }

    }

    public PSystemManager getModel() {
        return this.pSystemManager;
    }
}
